package me.yushuai.wukong.base.repository;

import me.yushuai.wukong.base.entity.PackingUom;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * 针对表【BAS_PACKAGE_DETAILS】的数据库操作Mapper
 *
 * @author zhoushuai@189.cn
 * @Entity me.yushuai.wukong.base.domain.PackageDetails
 * @since 2022-08-18
 */
@Repository
public interface PackingUomRepository extends JpaRepository<PackingUom, Long>, JpaSpecificationExecutor<PackingUom> {

    /**
     * Using the packingId and uomId delete a PackingUom.
     *
     * @param packingId packingId is id of PackingBasic
     * @param uomId     uomId is id of PackingUom
     */
    @Modifying
    @Query("delete from PackingUom where packingId = ?1 and uomId = ?2")
    void deleteByPackingIdAndUomId(Long packingId, Long uomId);

    @Query("from PackingUom where packingId = ?1 and uomId = ?2")
    Optional<PackingUom> findByPackingIdAndUomId(Long packingId, Long uomId);

    @Query("from PackingUom where packingId = ?1 and bizId =?2")
    Boolean existsByPackingIdAndPackingUomBizId(Long packingId, String packingUomBizId);

    @Query("from PackingUom  where  packingId = ?1")
    List<PackingUom> findByPackingId(Long packingId);

    @Query("from PackingUom where packingId = ?1 and uomId =?2")
    boolean existsById(Long packingId, Long uomId);
}




